package com.woniuxy.company5.security;

import com.woniuxy.company5.entity.UserEmp;
import com.woniuxy.company5.service.UserEmpService;
import com.woniuxy.company5.service.UserPermissionService;
import com.woniuxy.company5.vo.UserPermissionVo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：fengSir
 * @date ：Created By 2022-12-01 16:11
 * @description ：TODO
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private UserEmpService userService;
    @Autowired
    private UserPermissionService permissionService;
//    @Autowired
//    private RoleService roleService;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //得到实体信息
        UserEmp sysUser = userService.selectByAccount(username);
        //得到菜单
        List<UserPermissionVo> menuList = permissionService.selectMenu(1);
//        //得到当前用户的权限
        List<String> permissions = permissionService.selectByAccount(username);
//        //得到当前用户的角色
 //       List<String> roles = roleService.selectRolesByTel(username);
        LoginUser loginUser = new LoginUser();
        loginUser.setUser(sysUser);
        loginUser.setMenuList(menuList);
        loginUser.setPermissions(permissions);
 //       loginUser.setRoles(roles);
        return loginUser;
    }
}
